/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.volokh.danylo.sample_usage;

import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.ability.fraction.FractionManager;
import ohos.aafwk.content.Intent;

public class MainAbility extends FractionAbility {

    private PlaceholderFraction placeholderFraction = new PlaceholderFraction();
    private boolean isFractionAdded = false;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_main);
        addFraction();
    }

    @Override
    protected void onActive() {
        super.onActive();
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onPostActive() {
        super.onPostActive();
    }

    private void addFraction() {
        FractionManager fractionManager = getFractionManager();
        if (isFractionAdded) {
            fractionManager.startFractionScheduler().remove(placeholderFraction).submit();
        }
        fractionManager.startFractionScheduler()
                .add(ResourceTable.Id_container, placeholderFraction, PlaceholderFraction.class.getName())
                .submit();
        isFractionAdded = true;
    }
}
